home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / telecom / 46 / pascal / pr.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-08-15  |  6.9 KB  |  231 lines

  1. PROGRAM Pr ;
  2.     { Program to make a printout of a listing or file    }
  3.     { puts header with file name & date at top of page   }
  4.     { puts a footer with page number at bottom pf page   }
  5.     { uses item selector box to get the file to print    }
  6.     { WILLIAM R. GOOD JULY 1986                          }
  7.  
  8.   CONST
  9.     {$I GEMCONST.PAS}
  10.  
  11.   TYPE
  12.     {$I gemtype.pas}
  13.     prtype = FILE OF TEXT ;
  14.     tftype = FILE OF TEXT ;
  15.  
  16.   VAR
  17.     pathname, filename : Path_Name ;
  18.     selection : boolean ;
  19.     textfile : tftype ;
  20.     prtfile : prtype ;
  21.     result : integer ;
  22.  
  23.   {$I gemsubs}          { and that ".PAS" is default }
  24.  
  25. { the next two functions are added to personal pascal }
  26.  
  27. FUNCTION t_getdate : integer ;
  28.    GEMDOS( $2a ) ;
  29.  
  30. FUNCTION t_gettime : integer ;
  31.    GEMDOS( $2c ) ;
  32.  
  33. PROCEDURE info ;
  34.    { prints the copyright notice on the screen }
  35.    { in a alert box. OSS wants this            }
  36.    VAR
  37.        button : integer ;
  38.        alerttext : string[255] ;
  39.        part1, part2, part3, part4, part5 : string ;
  40.    BEGIN
  41.        part1 := '[3][Pr by William R. Good|' ;
  42.        part2 := 'Portions of this product are|' ;
  43.        part3 := 'Copyright (c) 1986 OSS and CCD|' ;
  44.        part4 := 'Used by Permission of OSS.|' ;
  45.        part5 := 'Written on 07-26-86 ][ OK ]' ;
  46.        alerttext := Concat ( part1, part2, part3, part4, part5 ) ;
  47.        button := Do_Alert(alerttext,1) ;
  48.    END ; { info }
  49.  
  50. PROCEDURE another ( var selection : integer ) ;
  51.    { procedure to get a yes or no answer }
  52.    VAR
  53.       alerttext : string[255] ;
  54.    BEGIN
  55.       alerttext := '[2][Do another file][ YES | NO ]' ;
  56.       selection := Do_Alert(alerttext,2) ;  { default no }
  57.    END ; { another }
  58.  
  59. PROCEDURE Inttostr (int : integer; VAR inttext : string) ;
  60. {Generic procedure to convert integers to strings, packs front with zeros.}
  61. VAR
  62.    place,digit : integer;
  63.    tempstr : string ;
  64. BEGIN
  65.    tempstr := '' ;
  66.    FOR place:=1 DOWNTO 0 DO
  67.       BEGIN
  68.          digit:=int DIV Round(PwrOfTen(place));
  69.          tempstr := concat (tempstr, chr(digit+ord('0'))) ;
  70.          int:=int MOD Round(PwrOfTen(place));
  71.       END;
  72.    inttext := tempstr ;
  73. END; {Inttostr}
  74.  
  75. PROCEDURE getdate (var datestr : string ) ;
  76. { procedure to return the date in a string }
  77.    VAR
  78.       dateint,tempint,
  79.       yearint, monthint, dayint : integer ;
  80.       yearstr, monthstr, daystr : string ;
  81.    BEGIN
  82.       dateint := t_getdate ;
  83.       yearint := dateint div 512 ;
  84.       yearint := yearint + 80 ;
  85.       tempint := dateint mod 512 ;
  86.       monthint := tempint div 32 ;
  87.       dayint := tempint mod 32 ;
  88.       inttostr( yearint, yearstr ) ;
  89.       inttostr( monthint, monthstr ) ;
  90.       inttostr( dayint, daystr ) ;
  91.       datestr := concat( monthstr, '/', daystr, '/', yearstr ) ;
  92.    END ; { getdate }
  93.  
  94. PROCEDURE gettime (var timestr : string ) ;
  95. { procedure to return the time in a string }
  96.    VAR
  97.       timeint, tempint, tmpint,
  98.       hourint, minint, secint : integer ;
  99.       hourstr, minstr, secstr : string ;
  100.    BEGIN
  101.       timeint := t_gettime ;
  102.       tmpint := 0 ;
  103.       if timeint < 0 then
  104.          begin
  105.             timeint := $8000 + timeint ;
  106.             tmpint := 16 ;
  107.          end ;
  108.       hourint := timeint div $800 ;
  109.       tempint := timeint mod $800 ;
  110.       minint := tempint div $20 ;
  111.       secint := tempint mod $20 ;
  112.       secint := secint * 2 ;
  113.       hourint := hourint + tmpint ;
  114.       inttostr( hourint, hourstr ) ;
  115.       inttostr( minint, minstr ) ;
  116.       inttostr( secint, secstr ) ;
  117.       timestr := concat( hourstr, ':', minstr, ':', secstr ) ;
  118.    END ; { gettime }
  119.  
  120. PROCEDURE printhead ;
  121.         { prints header with full pathname  }
  122.         { and date                          }
  123.    var
  124.       times1, times2, len, tmplen : integer ;
  125.       headline, time, date, tabstr : string ;
  126.    begin
  127.       tabstr := ' ' ;
  128.       rewrite( prtfile, 'LST:' ) ;
  129.       for times1 := 1 to 2 do
  130.          begin
  131.             writeln( prtfile ) ;  { space down some lines }
  132.          end ;
  133.       getdate ( date ) ;
  134.       gettime ( time ) ;
  135.       len := length( filename ) ;
  136.       tmplen := 60 - len ;
  137.       repeat
  138.          tmplen := tmplen - 1 ;
  139.          tabstr := concat( tabstr, ' ' ) ;
  140.       until tmplen < 1 ;
  141.       headline := concat(filename, tabstr, time,' ', date ) ;
  142.       writeln( prtfile, headline ) ; { need to add filename here }
  143.       for times2 := 1 to 2 do
  144.          begin
  145.             writeln( prtfile ) ;
  146.          end ;
  147.    end ; { printhead }
  148.  
  149. PROCEDURE printfoot( pagenum : integer ) ;
  150.         { prints footer with page number  }
  151.         { at the bottom of page in center }
  152.    var 
  153.       line, textline : string ;
  154.       pagestr : string ;
  155.       tempnum, index, times1, times2 : integer ;
  156.    begin
  157.       rewrite( prtfile, 'LST:' ) ;
  158.       for times1 := 1 to 2 do
  159.          begin
  160.             writeln( prtfile ) ;
  161.          end ;
  162.       inttostr( pagenum, pagestr ) ;
  163.       textline := '                             PAGE NUMBER : ' ;
  164.       textline := concat( textline, pagestr ) ;
  165.       writeln( prtfile, textline ) ;
  166.       for times2 := 1 to 2 do
  167.          begin
  168.             writeln( prtfile ) ;
  169.          end
  170.    end ; { printfoot}
  171.  
  172. PROCEDURE printfile ;
  173.    { prints the pascal file to the printer       }
  174.    { prints header and footer with page number   }
  175.    VAR
  176.       textfile : tftype ;
  177.       prtfile : prtype ;
  178.       number, tempnum, strline : string ;
  179.       check, linecount, pagenumber : integer ;
  180.    BEGIN
  181.       pagenumber := 0 ;
  182.       linecount := 1 ;
  183.       rewrite( prtfile, 'LST:' ) ;
  184.       pathname := 'A:\*.*' ;
  185.       selection := true ;
  186.       selection := Get_In_File( pathname, filename ) ;
  187.       if selection then
  188.          begin
  189.          set_mouse(m_bee) ;
  190.          printhead ;
  191.          reset( textfile, filename ) ;
  192.          while (not eof( textfile )) do
  193.             begin
  194.                readln ( textfile, strline ) ;
  195.                writeln ( prtfile, strline ) ;
  196.                linecount := linecount + 1 ;
  197.                if linecount = 57 then
  198.                   begin
  199.                      pagenumber := pagenumber + 1 ;
  200.                      printfoot ( pagenumber ) ;
  201.                      printhead ;
  202.                      linecount := 1 ;
  203.                   end ;
  204.             end ;
  205.             if linecount < 57 then
  206.                begin
  207.                   repeat
  208.                      writeln ( prtfile ) ;
  209.                      linecount := linecount + 1 ;
  210.                   until linecount = 57 ;
  211.                   pagenumber := pagenumber + 1 ;
  212.                   printfoot ( pagenumber ) ;
  213.                end ;
  214.          set_mouse(m_arrow) ;
  215.          end ;         
  216.    end ; { end printfile }
  217.  
  218.   BEGIN  {Main Module}
  219.     IF Init_Gem >= 0 THEN
  220.       BEGIN
  221.          info ;
  222.          repeat
  223.             printfile ;
  224.             close( textfile ) ;
  225.             close( prtfile ) ;
  226.             another( result ) ;
  227.          until result <> 1 ;
  228.          Exit_Gem ;
  229.       END ;
  230.   END. { Pr }
  231.